<?php
  class messages extends user 
  {
	 /**
	 * get User All Messages
	 * 
	 * @param mixed $MessageID
	 */
	 public function getUserMessage($MessageID = false)
	 {
		$MessageSQLText = " SELECT * FROM snm_messages WHERE receiver = ".$this->userID;
		if($MessageID)
		{
			$MessageSQLText .= " AND id =".$MessageID;
			$this->db->sql(" UPDATE snm_messages SET read = 1 WHERE id = ".intval($MessageID));
		}
		$MessageSQL = $this->db->sql($MessageSQLText);
		return $this->db->getir($MessageSQL);
	 }
	 
	 /**
	 * Count Messages
	 * 
	 * @param mixed $onlyNew
	 */
	 public function countMessage($onlyNew = false)
	 {
		$newMessageCountSQL = " SELECT count(*) as toplam FROM snm_messages WHERE receiver = ".$this->userID;
		if($onlyNew)
		{
			$newMessageCountSQL .= " AND read = 0 ";
		}
		$newMessageCount = $this->db->getir($newMessageCountSQL);
		return $newMessageCount['toplam'];
	 }
	 
  }
?>
